/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package main.java.cn.webrx;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * <p>Project: jse2204 - BufferedStreamDemo
 * <p>Powered by webrx On 2022-09-23 14:01:25
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class BufferedStreamDemo {
    public static void main(String[] args) {
        String s = "c:/abc/g1.jpg";

        long ss = System.currentTimeMillis();
        try(FileInputStream fis = new FileInputStream(s)) {
            int a = 0;
            while(fis.read()!=-1){
                ++a;
            }
            System.out.println(a);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.printf("FileInputStream:%dms",System.currentTimeMillis()-ss);

        System.out.println();
        ss = System.currentTimeMillis();
        try(BufferedInputStream bis = new BufferedInputStream(new FileInputStream(s))) {
            //int a = 0;
            //while(bis.read()!=-1){
            //    ++a;
            //}
            //System.out.println(a);
            byte[] buf = new byte[bis.available()];
            bis.read(buf);
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        System.out.printf("BufferedInputStream:%dms",System.currentTimeMillis()-ss);




    }
}
